package com.zhangsun.config;

import com.zhangsun.common.RabbitMqFanoutConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Fanout模式消息队列
 */
@Configuration
public class RabbitMqFanoutConfig {

    /**
     * 消息队列
     *
     * @return 消息队列
     */
    @Bean
    public Queue hello1() {
        return new Queue(RabbitMqFanoutConstant.FANOUT_QUEUE_HELLO_1);
    }

    /**
     * 消息队列
     *
     * @return 消息队列
     */
    @Bean
    public Queue hello2() {
        return new Queue(RabbitMqFanoutConstant.FANOUT_QUEUE_HELLO_2);
    }

    /**
     * Fanout交换器
     *
     * @return 交换器
     */
    @Bean
    public FanoutExchange fanoutHelloExchange() {
        return new FanoutExchange(RabbitMqFanoutConstant.FANOUT_EXCHANGE_HELLO);
    }

    /**
     * 绑定交换器
     *
     * @return 绑定交换器
     */
    @Bean
    public Binding fanoutBinding1() {
        return BindingBuilder.bind(hello1()).to(fanoutHelloExchange());
    }

    /**
     * 绑定交换器
     *
     * @return 绑定交换器
     */
    @Bean
    public Binding fanoutBinding2() {
        return BindingBuilder.bind(hello2()).to(fanoutHelloExchange());
    }

}
